<?php

/**
 * 网站管理后台首页
 * File Name：PublicController.php
 * File Encoding：UTF-8
 * File New Time：2014-4-29 15:50:31
 * Author：水平凡
 * Mailbox：admin@abc3210.com
 */
class IndexController extends AdminBase {

    //后台首页
    public function actionIndex() {
        if (IS_AJAX) {
            $data = array();
            $data['info'] = 'by admin@abc3210.com';
            $data['status'] = 1;
            $data['referer'] = $data['url'] = '';
            $this->ajaxReturn($data);
            exit;
        }
        $this->assign("SUBMENU_CONFIG", json_encode(Menu::model()->getMenuList()));
        $this->assign('uid', self::$uid);
        $this->assign('username', self::$username);
        $this->assign('userInfo', self::$userInfo);
        $this->assign('config', ConfigModel::model()->getConfig());
        $this->render();
    }

    //显示后台登录首页
    public function actionMain() {
        $this->render();
    }

    //退出登录
    public function actionLogout() {
        Yii::app()->passport->logoutLocal();
        $this->success('退出登录成功！', $this->createUrl('public/login'));
    }

    //清除全部缓存
    public function actionFlush() {
        Yii::app()->cache->flush();
        $this->success('缓存更新成功！', self::U('main'));
    }

    //信息通知
    public function actionPublic_notice() {
        $data = AdminMessage::model()->getNotice(self::$uid);
        if (empty($data) || empty($data['extendParams'])) {
            $this->ajaxReturn(array('status' => false));
        }
        $return = array(
            'status' => true,
            'time' => time(),
        );
        switch ((int) $data['typeId']) {
            case 0:
                $return['content'] = $data['extendParams']['content'];
                break;
            case 1:
                $return['content'] = $data['extendParams']['content'];
                break;
            case 2:
                $return['content'] = '<table width="350" border="0" cellspacing="0" cellpadding="0" >
  <tr>
    <td width="120" height="120" align="center" valign="middle"><img src="' . $data['extendParams']['product_img'] . '" width="120" height="120" style="border:1px solid #eee" align="left"></td>
    <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-size:12px;">
      <tr>
        	<td height="25" width="30%"  style="text-align: right;">商品名称：</td>
        	<td height="25">' . $data['extendParams']['goods_name'] . '</td>
      </tr>
      <tr>
        	<td height="25"  width="30%" style="text-align: right;">活动价：</td>
        	<td>' . $data['extendParams']['promo_price'] . '</td>
      </tr>
      <tr>
        	<td height="25" width="30%"  style="text-align: right;">上架时间：</td>
        	<td>' . $data['extendParams']['start_time'] . '</td>
      </tr>
      <tr>
        	<td height="25" width="30%"  style="text-align: right;">下架时间：</td>
        <td>' . $data['extendParams']['end_time'] . '</td>
      </tr>
      <tr>
        	<td height="25" width="30%"  style="text-align: right;">审核人：</td>
        <td>' . $data['extendParams']['admin_username'] . '</td>
      </tr>
    </table></td>
  </tr>
</table>';
                break;
            default:
                $return['content'] = $data['extendParams']['content'];
                break;
        }
        $this->ajaxReturn($return);
    }

}
